<template>
  <span>
      <el-dialog
        :visible.sync="selectImgDialogVisible"
        width="90%"
        style="height: 100%;"
        title="选择爬取任务的图片"
        :z-index="9999"
        modal-append-to-body
        :close-on-click-modal="false"
        class="editAllImagedialog"
      >
      <div class="fill-width-height dialog-content flex-col">
        <SelectData
          ref="imageCrawlerRef"
          :isShowBillTab="false"
          class="flex-1"
          style="min-height: 0;overflow: hidden"
        />
        <el-divider style="margin: 0"/>
        <div class="d-flex align-center justify-center" style="margin-top: 10px;">
          <el-button type="danger" @click="deleteImages">删除</el-button>
          <!--        <el-button type="primary" @click="configSelect">确定</el-button>-->
        </div>
      </div>
    </el-dialog>

    <ConfigDialog ref="confirDelDialog" @handleConfirm="handleConfirm"></ConfigDialog>
  </span>
</template>

<script>
import SelectData from './selectData'
import {deleteImage} from "@/api/imgManage/imageCrawler";
import ConfigDialog from './confirDelDialog'
export default {
  name: '',
  components: {
    SelectData,
    ConfigDialog
  },
  props: {},
  data() {
    return {
      selectImgDialogVisible: false,
      isPermanentDelete: false,
      visible: false,
      checked: false
    }
  },
  computed: {},
  methods: {
    showDialog(){
      this.checked = false
      this.selectImgDialogVisible = true
    },
    async handleConfirm(checked){
      this.$modal.loading("正在处理数据，请稍候...");
      const data = this.$refs.imageCrawlerRef?.getSelectedData() || [];
      const selectedIds = data.map(item => item.imageId)
      const res = await deleteImage({ fildIds: selectedIds.join(','),isAddBlackList: checked }).catch(e => {
        this.$modal.closeLoading()
      })
      if(res.code == 200){
        this.$refs.confirDelDialog.closeDialog()
        this.$modal.closeLoading()
        this.$message.success('删除成功')
        this.$refs.imageCrawlerRef?.init()
      } else {
        this.$message.error('删除失败')
      }
    },
    deleteImages(){
      this.$refs.confirDelDialog.showDialog()
    }
  },
  mounted() {

  }
}
</script>


<style lang="scss" >
  .editAllImagedialog{
      .el-dialog{
        height: 90% !important;
      }
      .el-dialog__body{
        height: calc(100% - 54px);
      }
  }
</style>
